<script type="text/javascript">
$(function(){
	var pg = App.base.libEdit.ui, pp = pg.params || { type: 0 };
	
	var frm = {
		name: pg.seek('name'),
		ver: pg.seek('ver'),
		type: pg.seek('type'),
		code: pg.seek('code'),
		level: pg.seek('level'),
		memo: pg.seek('memo'),
		sourceParent: pg.seek('sourceParent'),
		sourceCode: pg.seek('sourceCode'),
		sourcePath: pg.seek('sourcePath'),
		exportCode: pg.seek('exportCode'),
		compileCode: pg.seek('compileCode'),
		packPath: pg.seek('packPath')
	}
	
	frm.type.mac('combo', {
		width: frm.name.width(),
		boxWidth: frm.name.width() + 1,
		data: Cache.base.lib.type
	}).val(0);
	
	function getValues(){
		return {
			id: pp.id,
			parentId: pp.parent,
			name: frm.name.val(),
			ver: frm.ver.val(),
			type: frm.type.selected[0],// 0jar包，1war包 
			code: frm.code.val(),
			level: frm.level.val(),
			memo: frm.memo.val(),
			
			sourceParent: frm.sourceParent.val(),
			sourcePath: frm.sourcePath.val(),
			sourceCode: frm.sourceCode.val(),
			exportCode: frm.exportCode.val(),
			compileCode: frm.compileCode.val(),
			packPath: frm.packPath.val()
		};
	}
	function setValues(o, pom){
		pg.seek('title').html(o.id? '编辑库':'添加库');
		frm.name.val(o.name);
		frm.ver.val(o.ver);
		frm.type.val(o.type);
		frm.code.val(o.code);
		frm.level.val(o.level);
		frm.memo.val(o.memo);
		
		frm.sourceParent.val(o.sourceParent);
		frm.exportCode.val(o.exportCode);
		frm.compileCode.val(o.compileCode);
		frm.sourceCode.val(o.sourceCode);
		frm.sourcePath.val(o.sourcePath);
		frm.packPath.val(o.packPath);
	}
	function validate(p){
		var x = App.validate, v=App.base.validation
		msg=pg.seek('msg').html('');
		return x(v.lib.name, p.name, msg, '名字')&&
			   x(v.lib.code, p.code, msg, '编码')&&
			   x(v.lib.ver, p.ver, msg, '版本号')&&
			   x(v.lib.level, p.level, msg, '优先级');
	}
	pg.find("input").blur(function(){
		var pms = getValues();
		if(!validate(pms))
			return;
	});
	
	pg.seek('ok').click(function(){
		var pms = getValues();
		if(!validate(pms)) {
			return;
		}
		$.post(App.ctx + '/lib/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);//更新树	
				if(pg.close){
					pg.close();
				}else{
					//pg.callback(null, pp.id || pp.parent);
				}
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	setValues(pp);
	
	pg.seek('close').click(function(){
		if (pg.close) {
			pg.close();
		} else {
			pg.callback(null, pp.id || pp.parent);
		}
	})

	if (pp.id) {
		/* frm.name.attr('readonly', true); */
		var w = mac.wait('Loading');
		$.get(App.ctx + '/lib/get.do', {
			id: pp.id
		}, function(rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				setValues(ro.data, '');
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
			w.close();
		});
	} else {
		setValues(pp);
	};
});
</script>
<div class="title">
	<span class="value" name="title" style="font-weight:bold;"></span>
</div>
<div class="form">
	<div class="item">
		<span class="label">名字：</span>
		<input type="text" name="name" placeholder="请填入库包的中文名字" /> 
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">编码：</span>
		<input type="text" name="code" placeholder="请填入库包的英文名字" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">版本号：</span>
		<input type="text" name="ver" placeholder="请填入库包的版本号" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">类型：</span>
		<div class="combo fl" name="type"></div>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">优先级：</span>
		<input type="number" name="level" value="0" />
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">源码根路径：</span>
		<input type="text" name="sourceParent" placeholder="请填入应用的源码根路径" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">源码相对路径：</span>
		<input type="text" name="sourcePath" placeholder="请填入应用的源码路径" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">源码构建：</span>
		<input type="text" name="sourceCode" placeholder="请填入源码构建" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">导出构建：</span>
		<input type="text" name="exportCode" placeholder="请填入导出构建" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">打包构建：</span>
		<input type="text" name="compileCode" placeholder="请填入打包构建" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">包生成路径：</span>
		<input type="text" name="packPath" placeholder="请填入应用包生成路径" />
		<span class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">备注：</span>
		<textarea name="memo"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label"></span>
		<span name="msg" class="msg"></span>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">确定</button>
		<button name="close">取消</button>
	</div>
</div>